var Data = require('./data.js');

var domains = Data.data.domains;
var io = require('socket.io')({
    origins: function(origin, next) {
        if ((origin in domains) && domains[origin] === true) {
            return next(null, true);
        } else {
            console.log('origin:', origin);
            return next(null, false);
        }
    }
}).listen(8900);

io.use(function(socket, next) {
    if (socket.request.headers.cookie) return next();
    next(new Error('Authentication error'));
});

module.exports = io;
